<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function Phone(name, age) {
      this.name = name,
        this.age = age
    }
    Phone.prototype.run = function () {
      console.log('跑的块');
    }
    // 封装一个方法
    function create(fn, ...arg) {
      const obj = {}
      const re = fn.apply(obj, arg)
      // 设置他的隐式原型指向其构造函数的显示原型
      obj.__proto__ = fn.prototype
      // re的类型是对象 他的值不为空 或他是函数 满足一个就行
      if (typeof re === 'object' && re !== null || typeof re === "function") {
        return re;
      } else {
        return obj
      }
    }
    const newPhone = create(Phone, '小米', 18)
    console.log(newPhone);
    newPhone.run()
  </script>
</body>

</html>